package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @description: 首页看板类型枚举
 * @Author: hongxiao
 * @date: 2019-02-27 17:09
 * @since v1.0
 */
@Getter
public enum BoardTypeEnum {
    /**
     * 首页看板类型枚举
     */
    WEB_LEFT(1,"webLeft", "enum.boardType.name.web_left"),


    WEB_RIGHT(2,"webRight", "enum.boardType.name.web_right"),


    DINGTALK(3,"dingtalk", "enum.boardType.name.dingtalk"),


    FOCUS_DINGTALK_CATEGORY(4,"focus_dingtalk_category", "enum.boardType.name.focus_dingtalk_category"),


    FOCUS_DINGTALK_WORK(5,"focus_dingtalk_work", "enum.boardType.name.focus_dingtalk_work"),

    ;

    /**
     * 枚举值 --
     */
    private final int code;
    /**
     * 枚举描述 --英文名称
     */
    private final String alias;
    /**
     * 枚举信息--中文名称
     */
    private final String name;

    BoardTypeEnum(int code, String alias, String name) {
        this.code = code;
        this.alias = alias;
        this.name = name;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code
     * @return TimeTypeEnum
     */
    public static BoardTypeEnum getByCode(Integer code) {
        if(code == null) {
            return null;
        }
        for (BoardTypeEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    public static List<String> getBoardAlias(){
        return new ArrayList<>(Arrays.asList(WEB_LEFT.getAlias(),WEB_RIGHT.getAlias(),DINGTALK.getAlias(),FOCUS_DINGTALK_CATEGORY.getAlias(),FOCUS_DINGTALK_WORK.getAlias()));
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    /**
     * 通过枚举 alias 获得枚举
     *
     * @param alias 枚举别名
     * @return AppStoreTypeEnum
     */
    public static BoardTypeEnum getByAlias(String alias) {
        for (BoardTypeEnum boardTypeEnum : values()) {
            if (boardTypeEnum.getAlias().equals(alias)) {
                return boardTypeEnum;
            }
        }
        return null;
    }

}
